//
//  HomeBaseViewController.m
//  OpenDoor
//
//  Created by cnmobi on 15/5/15.
//  Copyright (c) 2015年 CNMOBI. All rights reserved.
//

#import "HomeBaseViewController.h"

@interface HomeBaseViewController ()


@end

@implementation HomeBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.naviBar = self.navigationController.navigationBar;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    
    
    
    [self.view endEditing:YES];
}

- (void)setnav
{
    //去掉底线
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
        NSArray *list=self.navigationController.navigationBar.subviews;
        for (id obj in list) {
            if ([obj isKindOfClass:[UIImageView class]]) {
                UIImageView *imageView=(UIImageView *)obj;
                NSArray *list2=imageView.subviews;
                for (id obj2 in list2) {
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView2=(UIImageView *)obj2;
                        imageView2.hidden=YES;
                    }
                }
            }
        }
    }
    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

-(void)homeBaseCtlSetTitle:(NSString *)titleStr andWithBackType:(NavigationBack )backType
{
    
    if (titleStr) {
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        customLab.textAlignment = NSTextAlignmentCenter;
        [customLab setTextColor:[UIColor whiteColor]];
        [customLab setText:titleStr];
        customLab.font = [UIFont boldSystemFontOfSize:19];
        self.navigationItem.titleView = customLab;
    }
    
    if(backType == BackImage)
    {
        [self.naviBar setBackgroundImage:[UIImage imageNamed:@"123"] forBarMetrics:UIBarMetricsDefault];
    }
    else if (backType == BackColor) {
        [self.naviBar setBackgroundImage:[UIImage imageWithColor:RGB(57, 110, 222, 1) size:CGSizeMake(20, 64)] forBarMetrics:UIBarMetricsDefault];
    }
    else if (backType == BackZero)
    {
        [self.naviBar setBackgroundImage:[UIImage imageWithColor:RGB(57, 110, 222, 1) size:CGSizeMake(20, 64)] forBarMetrics:UIBarMetricsDefault];
        [self setnav];
    }
}

-(void)baseCtlSetLeftBtnImage:(UIImage *)leftImage andRightBtnImage:(UIImage *)rightImage
{
    
    if (leftImage) {
        
        self.leftNavgationItem = [[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:nil];
        self.leftNavgationItem.imageInsets = UIEdgeInsetsMake(0, -8, 0, 8);
        
        self.leftNavgationItem.tintColor = [UIColor whiteColor];
        //        ,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]
        self.navigationItem.leftBarButtonItems = @[self.leftNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];
        
    }
    if (rightImage) {
        self.rightNavgationItem = [[UIBarButtonItem alloc]initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:nil];
        self.rightNavgationItem.imageInsets = UIEdgeInsetsMake(0, -10, 0, 10);
        
        self.rightNavgationItem.tintColor = [UIColor whiteColor];
        
        self.navigationItem.rightBarButtonItems =  @[self.rightNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];;
        
    }
}
-(void)baseCtlSetLeftBtnTitle:(NSString *)leftTitle andWithRightTitle:(NSString *)rightTitle
{
    if (leftTitle) {
        
        _leftNavgationItem = [[UIBarButtonItem alloc]initWithTitle:leftTitle style:UIBarButtonItemStylePlain target:self action:nil];
        
        [_leftNavgationItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName,nil] forState:UIControlStateNormal];
        
        self.leftNavgationItem.tintColor = [UIColor whiteColor];
        self.navigationItem.leftBarButtonItems = @[self.leftNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];

    }
    if (rightTitle) {
        
        _rightNavgationItem = [[UIBarButtonItem alloc]initWithTitle:rightTitle style:UIBarButtonItemStylePlain target:self action:nil];
        [_rightNavgationItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName,nil] forState:UIControlStateNormal];
        
        self.rightNavgationItem.tintColor = [UIColor whiteColor];
        self.navigationItem.rightBarButtonItems =  @[self.rightNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];
        

    }
}



@end
